package cn.tedu.charging.account.dao.persist.repository.impl;

import cn.tedu.charging.account.dao.persist.mappers.ChargingStationMapper;
import cn.tedu.charging.account.dao.persist.repository.IChargingStationRepository;
import cn.tedu.charging.account.pojo.entity.ChargingStation;
import cn.tedu.charging.account.pojo.vo.ChargingStationStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * 处理充电站数据的存储库实现类
 *
 * @author wyy
 * @version 1.0
 */
@Slf4j
@Repository
public class ChargingStationRepositoryImpl implements IChargingStationRepository {

    @Autowired
    private ChargingStationMapper mapper;

    public ChargingStationRepositoryImpl() {
        log.info("创建存储库对象：ChargingStationRepositoryImpl");
    }

    @Override
    public int insert(ChargingStation chargingStation) {
        log.debug("开始执行【批量插入充电站】的数据访问，参数：{}", chargingStation);
        return mapper.insert(chargingStation);
    }

    @Override
    public int deleteById(Long id) {
        log.debug("开始执行【根据ID删除充电站】的数据访问，参数：{}", id);
        return mapper.deleteById(id);
    }

    @Override
    public int updateById(ChargingStation chargingStation) {
        log.debug("开始执行【更新充电站】的数据访问，参数：{}", chargingStation);
        return mapper.updateById(chargingStation);
    }

    @Override
    public int countByAddress(String address) {
        log.debug("开始执行【根据地址统计充电站的数量】的数据访问，参数：{}", address);
        QueryWrapper<ChargingStation> wrapper = new QueryWrapper<>();
        wrapper.eq("address", address);
        return mapper.selectCount(wrapper);
    }

    @Override
    public List<ChargingStation> selectBatchIds(Collection<Long> ids) {
        return mapper.selectBatchIds(ids);
    }

    @Override
    public List<ChargingStation> selectAll() {
        QueryWrapper<ChargingStation> wrapper = new QueryWrapper<>();
        return mapper.selectList(wrapper);
    }

    @Override
    public List<ChargingStationStandardVO> selectAllChargingDevice(Collection<Long> ids, String searchName) {
        List<ChargingStationStandardVO> chargingStationStandardVOS = mapper.selectChargingDeviceList(ids, searchName);
        return chargingStationStandardVOS;
    }
}
